package com.xmall.search.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmall.annotation.LoginRequiredFalse;
import com.xmall.define.base.Result;
import com.xmall.define.dto.es.EsSkuDto;
import com.xmall.define.dto.product.EsBaseAttrDto;
import com.xmall.define.request.es.EsSpuSearchRequest;
import com.xmall.search.service.other.IProductService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * elasticSearch
 */
@RestController
@RequestMapping("/service/search/product")
public class ProductController {

    @Resource
    private IProductService productService;

    /**
     * 更新索引映射
     */
    @LoginRequiredFalse
    @GetMapping("/updateMapping")
    public Result updateMapping(){
        productService.updateMapping();
        return Result.success();
    }

    /**
     * 总数
     */
    @LoginRequiredFalse
    @PostMapping("/count")
    public Result<Long> count(@Validated @RequestBody EsSpuSearchRequest request){
        return Result.success(productService.count(request));
    }

    /**
     * 规格参数
     */
    @LoginRequiredFalse
    @PostMapping("/baseAttrList")
    public Result<List<EsBaseAttrDto>> baseAttrList(@Validated @RequestBody EsSpuSearchRequest request){
        return Result.success(productService.baseAttrList(request));
    }

    /**
     * 分页列表
     */
    @LoginRequiredFalse
    @PostMapping("/listPage")
    public Result<Page<EsSkuDto>> listPage(@Validated @RequestBody EsSpuSearchRequest request){
        return Result.success(productService.listPage(request));
    }
}
